<template>
    <div class="alert-container" v-if="isShow">
        <div class="con">
            {{tip}}
        </div>
    </div>
</template>

<script>
export default {
    name:'alert',
    props:{
        tip:{
            type:String,
            default:'提示信息'
        },
        time:{
            type:Number,
            default:3
        }
    },
    data(){
        return {
            isShow:true,
            timer:null
        }
    },
    mounted(){
        this.timer = setTimeout(() => {
            this.isShow = false;
        },this.time*1000)
    },
    beforeDestroy(){
        clearTimeout(this.timer);
    }
}
</script>

<style scoped>
    .alert-container{
        width:100%;
        height: 100%;
        background: transparent;
        position: absolute;
        top:0;
        left:0;
    }

    .con{
        padding:5px;
        background: rgba(0,0,0,.5);
        color:#fff;
        position: absolute;
        left:50%;
        top:50%;
        transform: translate(-50%,-50%);
    }
</style>

